{extend name="base" /}
{block name="body"}
<div class="layui-card">
    <div class="layui-card-header">
        <div class="layui-form-item">
            <form action="{:url('crm/customer/index')}" class="layui-form" method="get">
                {if auth_url('crm/customer/add')}
                <div class="layui-inline" style="padding-left: 0px;">
                    <a href="{:url('crm/customer/add')}" class="layui-btn ajax-iframe" data-width="75%" data-height="100%">新增客户</a>
                </div>
                {/if}
                <div class="layui-inline">
                    <label class="layui-form-label w-auto">关键字：</label>
                    <div class="layui-input-inline mr0">
                        <input name="keywords" class="layui-input" value="{:input('keywords')}" type="text" placeholder="请输入客户名称" autocomplete="off"/>
                    </div>
                </div>
                {if field_status('industry','1')}
                <div class="layui-inline form-search-show-expand">
                    <label class="layui-form-label w-auto">行业：</label>
                    <div class="layui-input-inline mr0">
                        <select name="industry">
                            <option value="">请选择</option>
                            {foreach name=":get_dict_list('1')" key="k" item="r"}
                            <option value="{$k}" {if input('industry')==$k}selected{/if}>{$r}</option>
                            {/foreach}
                        </select>
                    </div>
                </div>
                {/if}
                {if field_status('source','1')}
                <div class="layui-inline form-search-show-expand">
                    <label class="layui-form-label w-auto">来源：</label>
                    <div class="layui-input-inline mr0">
                        <select name="source">
                            <option value="">请选择</option>
                            {foreach name=":get_dict_list('2')" key="k" item="r"}
                            <option value="{$k}" {if input('source')==$k}selected{/if}>{$r}</option>
                            {/foreach}
                        </select>
                    </div>
                </div>
                {/if}
                {if field_status('status','1')}
                <div class="layui-inline form-search-show-expand">
                    <label class="layui-form-label w-auto">状态：</label>
                    <div class="layui-input-inline mr0">
                        <select name="status">
                            <option value="">请选择</option>
                            {foreach name=":get_dict_list('4')" key="k" item="r"}
                            <option value="{$k}" {if input('status')==$k}selected{/if}>{$r}</option>
                            {/foreach}
                        </select>
                    </div>
                </div>
                {/if}
               
                <div class="layui-inline" style="padding-left: 20px;">
                    <button class="layui-btn layui-btn-primary ajax-search"><i class="fa fa-search"></i> 搜索</button>
                    <a class="layui-btn layui-btn-primary form-search-expand" data-expand="true">
                        展开 <i class="layui-icon layui-icon-down"></i>
                    </a>
                </div>
            </form>
        </div>
    </div>
    
    <table id="tableList" lay-filter="tableList"></table>
    <!-- 表格操作列 -->
    <script type="text/html" id="tableTBTrack">
        {if auth_url('crm/customer/index')}
        <a href="{:url('crm/detail/index')}?id={{d.id}}" class="layui-btn layui-btn-warm layui-btn-sm ajax-detail">详情</a>
        {/if}
        {if auth_url('crm/customer/edit')}
        <a href="{:url('crm/customer/edit')}?id={{d.id}}" class="layui-btn layui-btn-sm ajax-iframe" data-width="70%" data-height="100%">修改</a>
        {/if}
        {if auth_url('crm/customer/del')}
        <a href="{:url('crm/customer/del')}?id={{d.id}}" class="layui-btn layui-btn-danger layui-btn-sm ajax-delete">删除</a>
        {/if}
    </script>
    <!-- 权限列 -->
    <script type="text/html" id="status">
        <input type="checkbox" name="status" lay-skin="switch" lay-filter="*" lay-text="正常|锁定" data-url="{:url('crm/customer/edit')}?id={{d.id}}" {{d.status==1?'checked':''}}>
    </script>
    <!-- 权限列 -->
    <script type="text/html" id="sort_order">
        <input type="text" name="sort_order" value="{{d.sort_order}}" autocomplete="off" class="layui-input ajax-update" data-url="{:url('crm/customer/edit')}?id={{d.id}}">
    </script>
    <!-- 权限列 -->
    <script type="text/html" id="shengshi">
        {{d.province}}{{d.city}}{{d.area}}
    </script>
    <!-- 权限列 -->
    <script type="text/html" id="user">
        {{#  layui.each(d.crmuser, function(index, item){ }}
            <button class="layui-btn layui-btn-primary layui-btn-xs">{{item.user_name}}</button>
        {{#  }); }}
    </script>
</div>
{/block}

{block name="js"}
<script>
    layui.use(['layer', 'form', 'table', 'util', 'dropdown','laytpl'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var util = layui.util;
        var dtree = layui.dtree;
        var admin = layui.admin;
        var dropdown = layui.dropdown;
        var index = layui.index;
        
        var keywords = "{:input('keywords')}";
        var industry = "{:input('industry')}";
        var source = "{:input('source')}";
        var status = "{:input('status')}";
        // 渲染回访表格
        var insTb = table.render({
            elem: '#tableList',
            url: "{:url('crm/customer/index_json')}",
            where:{
                keywords:keywords,
                industry:industry,
                source:source,
                status:status
            },
            page: true,
            cellMinWidth: 100,
            //toolbar:true ,
            limit:'15',
            limits:['15','30','50','100','200','500'],
            size:'lg',even:true,
            cols: [[
                {type:'numbers',title:'#'},
                {field: 'name', align: 'left', sort: true, title: '名称'},
                {align: 'left', sort: false, title: '地址',templet:'#shengshi'},
                {if field_status('industry','1')}
                {field: 'industry_name', align: 'left', sort: true, title: '行业'},
                {/if}
                {if field_status('source','1')}
                {field: 'source_name', align: 'left', sort: true, title: '来源'},
                {/if}
                {if field_status('level','1')}
                {field: 'level_name', align: 'left', sort: true, title: '级别'},
                {/if}
                {if field_status('status','1')}
                {field: 'status_name', align: 'left', sort: true, title: '状态'},
                {/if}
                {field: 'create_time', align: 'center', sort: true, title: '创建时间'},
                {align: 'left', sort: true, title: '员工',templet:'#user'},
                {align: 'center', sort: false, title: '排序',templet:'#sort_order',width:100},
                {align: 'center', toolbar: '#tableTBTrack', title: '操作', minWidth: 190}
            ]],
            parseData: function(res){ //res 即为原始返回的数据
                return {
                  "code": res.code, //解析接口状态
                  "msg": res.msg, //解析提示文本
                  "count": res.data.total, //解析数据长度
                  "data": res.data.data //解析数据列表
                };
            }
        });
    });
</script>
{/block}